package cn.itcast.web.controller;

import cn.itcast.domain.Product;
import cn.itcast.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;

/**
 * @author :HCH
 * @version : 1.0.0
 * @date :Created in 2019/7/10 16:39
 * @description :TODO
 * @modified :
 */
@Controller
@RequestMapping("/product")
@Slf4j
public class UserController {

    @Autowired
    private UserService userService;

    private static ModelAndView mv;

    @RequestMapping("/findAll.do")
    public ModelAndView findAll() {

        List<Product> productList = userService.findAll();
        mv = new ModelAndView("product-list");
        mv.addObject("productList", productList);

        return mv;
    }

    @RequestMapping("/save.do")
    public String save( Product product) {

        userService.save(product);

        return "redirect:findAll.do";
    }




}
